package com.optimatch.ui.view.customComponents.pages.creation_equipes;

import java.util.Vector;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.optimatch.ui.model.beans.Equipe;
import com.optimatch.ui.model.beans.Ville;

public class PanelList extends JTable {

	private static final long serialVersionUID = 1L;
	
	private DefaultTableModel model;
	
	public PanelList() {
		super();
		this.model = new DefaultTableModel(new String[]{"Equipe","Ville","Latitude","Longitude"},0);
		this.setModel(model);
	}
	
	public void ajouterEquipe(Equipe e) {
		Ville v = e.getVille();
		model.addRow(new String[]{e.getName(),v.getName(),""+v.getLatitude(),""+v.getLongitude()});
	}
	
	public void retirerEquipe(int i) {
		model.removeRow(i);
	}

	public boolean has(String nom, int col) {
		Vector data = model.getDataVector();
		int rows = data.size();
		int i = 0;
		boolean found = false;
		while (i < rows && !found) {
			found = ((Vector) data.elementAt(i)).elementAt(col).equals(nom);
			i++;
		}
		return found;
	}
	
	public boolean hasEquipe(String nomEquipe) {
		return has(nomEquipe,0);
	}
	
	public boolean hasVille(String nomVille) {
		return has(nomVille,1);
	}

}
